{% macro status_class(status) %}
  {# djlint:off #}
{% if status == "FAILURE" %}
error
{% elif status == "SUCCESS" %}
success
{% elif status == "PENDING" or status == "Unknown" %}
neutral
{% else %}
info
{% endif %}
  {# djlint:on #}
{% endmacro %}

{% macro worker_status(status) %}
  {% set result_class = status_class(status.status) %}
  <div class="alert alert-{{ result_class }} flex flex-col gap-1 items-start">
    <div class="flex flex-row items-center">
      <p class="text-base-content/60 text-[0.7rem]">
        Last Run <span class="mx-2 badge badge-xs">{{ status.status }}</span> at <b>'{{ status.last_run | format_datetime }}'</b>
      </p>
    </div>
    <div class="flex flex-row items-center">
      <p class="text-base-content/60 text-[0.7rem]">
        Last successful run: <b>{{ status.last_success | format_datetime }}</b>
      </p>
    </div>
    <div class="divider my-0"></div>
    <div class="flex flex-row">
      <span class="text-left">{{ status.result }}</span>
    </div>
  </div>
{% endmacro %}

{% macro worker_status_badge(status) %}
  {% set result_class = status_class(status.status) %}
  <div class="tooltip" data-tip="{{ status.result }}">
    <div title="{{ status.status }}" class="badge badge-{{ result_class }}">{{ status.status }}</div>
  </div>
{% endmacro %}

{% macro worker_badge(status, enabled=True) %}
  {% if not enabled %}
    <div title="Disabled" class="badge badge-warning">Disabled</div>
  {% else %}
    {{ worker_status_badge(status) }}
  {% endif %}
{% endmacro %}

{% macro worker_state(worker_id, worker_type, enabled) %}
  <div class="join join-horizontal" id="state_buttons">
    <button class="btn rounded-l join-item {% if enabled %}btn-primary{% endif %}"
            hx-post="/frontend/admin/toggle_{{ worker_type }}_state/{{ worker_id }}/enabled"
            hx-target="#state_buttons">Enabled</button>
    <button class="btn rounded-r join-item {% if not enabled %}btn-warning{% endif %}"
            hx-post="/frontend/admin/toggle_{{ worker_type }}_state/{{ worker_id }}/disabled"
            hx-target="#state_buttons">Disabled</button>
  </div>
{% endmacro %}
